package com.spring.controller.javastack.context;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by chenhs on 2018/6/14.
 */
@Component
public class SpringContextHolder2 {

    //直接注入
    @Resource
    private ApplicationContext ctx;

    //工具类
    private ApplicationContext ctx2;

    //从当前线程绑定获取
    private ApplicationContext ctx3;


    public void init(HttpServletRequest request) {
        ctx2 = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
    }

    public void init2() {
        ctx3 = ContextLoader.getCurrentWebApplicationContext();
    }


}
